package main

import (
	"chapter1/src/server"
	"fmt"
	"net"
	"net/rpc"
)

/**
 * Created with Goland.
 * User: 令狐飞侠
 * Date: 2022-1-29
 * Description: 驱动函数
 */
func main()  {
	tcpStr := "tcp"
	serverUrl := "127.0.0.1:8086"

	//1 注册接口struct（函数）
	err:=rpc.Register(new(server.LhServer))
	if err!=nil{
		fmt.Println("register publisher failed :",err.Error())
	}else{
		fmt.Println("register publisher sucessed:")
	}

	//2 启动server listen连接
	listenCon,err:=net.Listen(tcpStr,serverUrl)
	if err!=nil{
		fmt.Println("listern tcp failed:",err.Error())
	}else{
		fmt.Println("listern tcp sucessed:", serverUrl)
	}
	defer listenCon.Close()

	//3 启动rpc server listen连接
	rpc.Accept(listenCon)
	fmt.Println("rpc accept listern:")
}
